package com.woniuxy.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.order.entity.OrderWaste;
import com.woniuxy.order.entity.WasteType;
import com.woniuxy.order.mapper.OrderInfoMapper;
import com.woniuxy.order.mapper.OrderWasteMapper;
import com.woniuxy.order.mapper.WasteTypeMapper;
import com.woniuxy.order.service.IOrderWasteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zsd.waste.dto.OrderWasteDto;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-05-13
 */
@Service
public class OrderWasteServiceImpl extends ServiceImpl<OrderWasteMapper, OrderWaste> implements IOrderWasteService {

    @Resource
    private OrderWasteMapper orderWasteMapper;
    @Resource
    private WasteTypeMapper wasteTypeMapper;

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Override
    public List<OrderWasteDto> findOrderIdWaste(String ordernum,Integer pageNum,Integer pageSize) throws Exception {
        List<OrderWasteDto> orderWasteDtoList = new ArrayList<>();
        QueryWrapper<OrderWaste> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_num",ordernum);
        List<OrderWaste> list = orderWasteMapper.selectList(queryWrapper);
        if (list!=null){
            for (OrderWaste orderWaste:list){
                OrderWasteDto dto = new OrderWasteDto();
                WasteType wasteType = wasteTypeMapper.selectById(orderWaste.getSasteTypeId());
                dto.setWasteImage(orderWaste.getWasteImage());
                dto.setWasteInfo(orderWaste.getWasteInfo());
                dto.setSastePrice(orderWaste.getSastePrice());
                dto.setSasteAllPrice(orderWaste.getSasteAllPrice());
                dto.setSasteTypeName(wasteType.getWasteTypeName());
                dto.setUnit(orderWaste.getUnit());
                dto.setWeight(orderWaste.getWeight());
                orderWasteDtoList.add(dto);
            }
        }
        return orderWasteDtoList;
    }

}
